{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 查看当前挂载的数据集目录\n",
    "!ls /home/aistudio/data/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 查看个人持久化工作区文件\n",
    "!ls /home/aistudio/work/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "!pip install torch\n",
    "!pip install torchvision"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import torch\r\n",
    "import numpy as np\r\n",
    "from torch import nn\r\n",
    "from torch import optim\r\n",
    "from torch.autograd import Variable\r\n",
    "#求三点的圆心\r\n",
    "x_train = np.array([[0,2.2] ,[1,2.5] ,[2,2.2]]  ,dtype=np.float32 )\r\n",
    "x_train = torch.from_numpy(x_train)\r\n",
    "\r\n",
    "\r\n",
    "\r\n",
    "#print(\"x_train=\",x_train)\r\n",
    "c=np.array([[1.5],[1.5]]  ,dtype=np.float32 )\r\n",
    "c = torch.from_numpy(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#线性模型\r\n",
    "class CenterOfCircle(nn.Module):\r\n",
    "    def __init__(self):\r\n",
    "        super(CenterOfCircle, self).__init__()\r\n",
    "        self.linear = nn.Linear(6,2)  # 输入三点坐标3*2=6，输出一点坐标2*1=2\r\n",
    "\r\n",
    "    def forward(self, x):\r\n",
    "        out = self.linear(x.view(1,-1))\r\n",
    "        centerOf = out.view( [1,2] )\r\n",
    "        node =x.view([3,2])\r\n",
    "        loss=torch.std(torch.sqrt(  torch.mm( (node-centerOf)*(node-centerOf) ,Variable(c)) ))#求输出一点到三点距离的均方差\r\n",
    "\r\n",
    "\r\n",
    "        return out,loss\r\n",
    "\r\n",
    "model = CenterOfCircle()\r\n",
    "#优化函数\r\n",
    "optimizer = optim.Adam(model.parameters(), lr=1e-4 , betas=(0.9, 0.99))  #试过SGD效果差，使用Adm\r\n",
    "\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch[20/20000], loss: 0.928038\n",
      "Epoch[40/20000], loss: 0.910989\n",
      "Epoch[60/20000], loss: 0.893556\n",
      "Epoch[80/20000], loss: 0.875771\n",
      "Epoch[100/20000], loss: 0.857675\n",
      "Epoch[120/20000], loss: 0.839312\n",
      "Epoch[140/20000], loss: 0.820727\n",
      "Epoch[160/20000], loss: 0.801960\n",
      "Epoch[180/20000], loss: 0.783051\n",
      "Epoch[200/20000], loss: 0.764037\n",
      "Epoch[220/20000], loss: 0.744952\n",
      "Epoch[240/20000], loss: 0.725825\n",
      "Epoch[260/20000], loss: 0.706686\n",
      "Epoch[280/20000], loss: 0.687559\n",
      "Epoch[300/20000], loss: 0.668466\n",
      "Epoch[320/20000], loss: 0.649428\n",
      "Epoch[340/20000], loss: 0.630462\n",
      "Epoch[360/20000], loss: 0.611585\n",
      "Epoch[380/20000], loss: 0.592809\n",
      "Epoch[400/20000], loss: 0.574148\n",
      "Epoch[420/20000], loss: 0.555611\n",
      "Epoch[440/20000], loss: 0.537210\n",
      "Epoch[460/20000], loss: 0.518951\n",
      "Epoch[480/20000], loss: 0.500843\n",
      "Epoch[500/20000], loss: 0.482893\n",
      "Epoch[520/20000], loss: 0.465106\n",
      "Epoch[540/20000], loss: 0.447488\n",
      "Epoch[560/20000], loss: 0.430043\n",
      "Epoch[580/20000], loss: 0.412776\n",
      "Epoch[600/20000], loss: 0.395690\n",
      "Epoch[620/20000], loss: 0.378789\n",
      "Epoch[640/20000], loss: 0.362075\n",
      "Epoch[660/20000], loss: 0.345552\n",
      "Epoch[680/20000], loss: 0.329222\n",
      "Epoch[700/20000], loss: 0.313087\n",
      "Epoch[720/20000], loss: 0.297149\n",
      "Epoch[740/20000], loss: 0.281410\n",
      "Epoch[760/20000], loss: 0.265872\n",
      "Epoch[780/20000], loss: 0.250536\n",
      "Epoch[800/20000], loss: 0.235406\n",
      "Epoch[820/20000], loss: 0.220481\n",
      "Epoch[840/20000], loss: 0.205766\n",
      "Epoch[860/20000], loss: 0.191261\n",
      "Epoch[880/20000], loss: 0.176971\n",
      "Epoch[900/20000], loss: 0.162898\n",
      "Epoch[920/20000], loss: 0.149048\n",
      "Epoch[940/20000], loss: 0.135427\n",
      "Epoch[960/20000], loss: 0.122042\n",
      "Epoch[980/20000], loss: 0.108906\n",
      "Epoch[1000/20000], loss: 0.096031\n",
      "Epoch[1020/20000], loss: 0.083435\n",
      "Epoch[1040/20000], loss: 0.071144\n",
      "Epoch[1060/20000], loss: 0.059189\n",
      "Epoch[1080/20000], loss: 0.047620\n",
      "Epoch[1100/20000], loss: 0.036557\n",
      "Epoch[1120/20000], loss: 0.026366\n",
      "Epoch[1140/20000], loss: 0.018087\n",
      "Epoch[1160/20000], loss: 0.013000\n",
      "Epoch[1180/20000], loss: 0.009618\n",
      "Epoch[1200/20000], loss: 0.006326\n",
      "Epoch[1220/20000], loss: 0.003138\n",
      "Epoch[1240/20000], loss: 0.000015\n",
      "Epoch[1260/20000], loss: 0.000213\n",
      "Epoch[1280/20000], loss: 0.000096\n",
      "Epoch[1300/20000], loss: 0.000085\n",
      "Epoch[1320/20000], loss: 0.000047\n",
      "Epoch[1340/20000], loss: 0.000060\n",
      "Epoch[1360/20000], loss: 0.000037\n",
      "Epoch[1380/20000], loss: 0.000053\n",
      "Epoch[1400/20000], loss: 0.000022\n",
      "Epoch[1420/20000], loss: 0.000038\n",
      "Epoch[1440/20000], loss: 0.000038\n",
      "Epoch[1460/20000], loss: 0.000033\n",
      "Epoch[1480/20000], loss: 0.000032\n",
      "Epoch[1500/20000], loss: 0.000032\n",
      "Epoch[1520/20000], loss: 0.000037\n",
      "Epoch[1540/20000], loss: 0.000047\n",
      "Epoch[1560/20000], loss: 0.000027\n",
      "Epoch[1580/20000], loss: 0.000038\n",
      "Epoch[1600/20000], loss: 0.000038\n",
      "Epoch[1620/20000], loss: 0.000028\n",
      "Epoch[1640/20000], loss: 0.000035\n",
      "Epoch[1660/20000], loss: 0.000038\n",
      "Epoch[1680/20000], loss: 0.000041\n",
      "Epoch[1700/20000], loss: 0.000028\n",
      "Epoch[1720/20000], loss: 0.000045\n",
      "Epoch[1740/20000], loss: 0.000033\n",
      "Epoch[1760/20000], loss: 0.000035\n",
      "Epoch[1780/20000], loss: 0.000043\n",
      "Epoch[1800/20000], loss: 0.000047\n",
      "Epoch[1820/20000], loss: 0.000033\n",
      "Epoch[1840/20000], loss: 0.000034\n",
      "Epoch[1860/20000], loss: 0.000037\n",
      "Epoch[1880/20000], loss: 0.000030\n",
      "Epoch[1900/20000], loss: 0.000098\n",
      "Epoch[1920/20000], loss: 0.000067\n",
      "Epoch[1940/20000], loss: 0.000102\n",
      "Epoch[1960/20000], loss: 0.000069\n",
      "Epoch[1980/20000], loss: 0.000052\n",
      "Epoch[2000/20000], loss: 0.000099\n",
      "Epoch[2020/20000], loss: 0.000067\n",
      "Epoch[2040/20000], loss: 0.000057\n",
      "Epoch[2060/20000], loss: 0.000065\n",
      "Epoch[2080/20000], loss: 0.000035\n",
      "Epoch[2100/20000], loss: 0.000043\n",
      "Epoch[2120/20000], loss: 0.000046\n",
      "Epoch[2140/20000], loss: 0.000039\n",
      "Epoch[2160/20000], loss: 0.000037\n",
      "Epoch[2180/20000], loss: 0.000043\n",
      "Epoch[2200/20000], loss: 0.000038\n",
      "Epoch[2220/20000], loss: 0.000038\n",
      "Epoch[2240/20000], loss: 0.000044\n",
      "Epoch[2260/20000], loss: 0.000041\n",
      "Epoch[2280/20000], loss: 0.000038\n",
      "Epoch[2300/20000], loss: 0.000049\n",
      "Epoch[2320/20000], loss: 0.000045\n",
      "Epoch[2340/20000], loss: 0.000027\n",
      "Epoch[2360/20000], loss: 0.000034\n",
      "Epoch[2380/20000], loss: 0.000035\n",
      "Epoch[2400/20000], loss: 0.000038\n",
      "Epoch[2420/20000], loss: 0.000036\n",
      "Epoch[2440/20000], loss: 0.000042\n",
      "Epoch[2460/20000], loss: 0.000048\n",
      "Epoch[2480/20000], loss: 0.000042\n",
      "Epoch[2500/20000], loss: 0.000047\n",
      "Epoch[2520/20000], loss: 0.000034\n",
      "Epoch[2540/20000], loss: 0.000054\n",
      "Epoch[2560/20000], loss: 0.000057\n",
      "Epoch[2580/20000], loss: 0.000042\n",
      "Epoch[2600/20000], loss: 0.000008\n",
      "Epoch[2620/20000], loss: 0.000086\n",
      "Epoch[2640/20000], loss: 0.000077\n",
      "Epoch[2660/20000], loss: 0.000064\n",
      "Epoch[2680/20000], loss: 0.000107\n",
      "Epoch[2700/20000], loss: 0.000070\n",
      "Epoch[2720/20000], loss: 0.000047\n",
      "Epoch[2740/20000], loss: 0.000098\n",
      "Epoch[2760/20000], loss: 0.000066\n",
      "Epoch[2780/20000], loss: 0.000048\n",
      "Epoch[2800/20000], loss: 0.000060\n",
      "Epoch[2820/20000], loss: 0.000040\n",
      "Epoch[2840/20000], loss: 0.000049\n",
      "Epoch[2860/20000], loss: 0.000071\n",
      "Epoch[2880/20000], loss: 0.000063\n",
      "Epoch[2900/20000], loss: 0.000054\n",
      "Epoch[2920/20000], loss: 0.000045\n",
      "Epoch[2940/20000], loss: 0.000035\n",
      "Epoch[2960/20000], loss: 0.000039\n",
      "Epoch[2980/20000], loss: 0.000042\n",
      "Epoch[3000/20000], loss: 0.000028\n",
      "Epoch[3020/20000], loss: 0.000049\n",
      "Epoch[3040/20000], loss: 0.000043\n",
      "Epoch[3060/20000], loss: 0.000042\n",
      "Epoch[3080/20000], loss: 0.000042\n",
      "Epoch[3100/20000], loss: 0.000037\n",
      "Epoch[3120/20000], loss: 0.000038\n",
      "Epoch[3140/20000], loss: 0.000043\n",
      "Epoch[3160/20000], loss: 0.000039\n",
      "Epoch[3180/20000], loss: 0.000039\n",
      "Epoch[3200/20000], loss: 0.000030\n",
      "Epoch[3220/20000], loss: 0.000043\n",
      "Epoch[3240/20000], loss: 0.000029\n",
      "Epoch[3260/20000], loss: 0.000045\n",
      "Epoch[3280/20000], loss: 0.000044\n",
      "Epoch[3300/20000], loss: 0.000051\n",
      "Epoch[3320/20000], loss: 0.000028\n",
      "Epoch[3340/20000], loss: 0.000038\n",
      "Epoch[3360/20000], loss: 0.000039\n",
      "Epoch[3380/20000], loss: 0.000038\n",
      "Epoch[3400/20000], loss: 0.000043\n",
      "Epoch[3420/20000], loss: 0.000040\n",
      "Epoch[3440/20000], loss: 0.000045\n",
      "Epoch[3460/20000], loss: 0.000034\n",
      "Epoch[3480/20000], loss: 0.000044\n",
      "Epoch[3500/20000], loss: 0.000055\n",
      "Epoch[3520/20000], loss: 0.000030\n",
      "Epoch[3540/20000], loss: 0.000015\n",
      "Epoch[3560/20000], loss: 0.000068\n",
      "Epoch[3580/20000], loss: 0.000073\n",
      "Epoch[3600/20000], loss: 0.000055\n",
      "Epoch[3620/20000], loss: 0.000055\n",
      "Epoch[3640/20000], loss: 0.000036\n",
      "Epoch[3660/20000], loss: 0.000042\n",
      "Epoch[3680/20000], loss: 0.000049\n",
      "Epoch[3700/20000], loss: 0.000046\n",
      "Epoch[3720/20000], loss: 0.000043\n",
      "Epoch[3740/20000], loss: 0.000045\n",
      "Epoch[3760/20000], loss: 0.000039\n",
      "Epoch[3780/20000], loss: 0.000039\n",
      "Epoch[3800/20000], loss: 0.000039\n",
      "Epoch[3820/20000], loss: 0.000042\n",
      "Epoch[3840/20000], loss: 0.000040\n",
      "Epoch[3860/20000], loss: 0.000045\n",
      "Epoch[3880/20000], loss: 0.000028\n",
      "Epoch[3900/20000], loss: 0.000046\n",
      "Epoch[3920/20000], loss: 0.000043\n",
      "Epoch[3940/20000], loss: 0.000040\n",
      "Epoch[3960/20000], loss: 0.000021\n",
      "Epoch[3980/20000], loss: 0.000029\n",
      "Epoch[4000/20000], loss: 0.000059\n",
      "Epoch[4020/20000], loss: 0.000066\n",
      "Epoch[4040/20000], loss: 0.000027\n",
      "Epoch[4060/20000], loss: 0.000090\n",
      "Epoch[4080/20000], loss: 0.000062\n",
      "Epoch[4100/20000], loss: 0.000047\n",
      "Epoch[4120/20000], loss: 0.000100\n",
      "Epoch[4140/20000], loss: 0.000068\n",
      "Epoch[4160/20000], loss: 0.000049\n",
      "Epoch[4180/20000], loss: 0.000098\n",
      "Epoch[4200/20000], loss: 0.000070\n",
      "Epoch[4220/20000], loss: 0.000051\n",
      "Epoch[4240/20000], loss: 0.000087\n",
      "Epoch[4260/20000], loss: 0.000053\n",
      "Epoch[4280/20000], loss: 0.000029\n",
      "Epoch[4300/20000], loss: 0.000008\n",
      "Epoch[4320/20000], loss: 0.000053\n",
      "Epoch[4340/20000], loss: 0.000037\n",
      "Epoch[4360/20000], loss: 0.000127\n",
      "Epoch[4380/20000], loss: 0.000051\n",
      "Epoch[4400/20000], loss: 0.000046\n",
      "Epoch[4420/20000], loss: 0.000098\n",
      "Epoch[4440/20000], loss: 0.000071\n",
      "Epoch[4460/20000], loss: 0.000053\n",
      "Epoch[4480/20000], loss: 0.000097\n",
      "Epoch[4500/20000], loss: 0.000068\n",
      "Epoch[4520/20000], loss: 0.000053\n",
      "Epoch[4540/20000], loss: 0.000023\n",
      "Epoch[4560/20000], loss: 0.000041\n",
      "Epoch[4580/20000], loss: 0.000029\n",
      "Epoch[4600/20000], loss: 0.000012\n",
      "Epoch[4620/20000], loss: 0.000174\n",
      "Epoch[4640/20000], loss: 0.000113\n",
      "Epoch[4660/20000], loss: 0.000065\n",
      "Epoch[4680/20000], loss: 0.000106\n",
      "Epoch[4700/20000], loss: 0.000062\n",
      "Epoch[4720/20000], loss: 0.000046\n",
      "Epoch[4740/20000], loss: 0.000101\n",
      "Epoch[4760/20000], loss: 0.000067\n",
      "Epoch[4780/20000], loss: 0.000051\n",
      "Epoch[4800/20000], loss: 0.000098\n",
      "Epoch[4820/20000], loss: 0.000064\n",
      "Epoch[4840/20000], loss: 0.000035\n",
      "Epoch[4860/20000], loss: 0.000033\n",
      "Epoch[4880/20000], loss: 0.000034\n",
      "Epoch[4900/20000], loss: 0.000036\n",
      "Epoch[4920/20000], loss: 0.000034\n",
      "Epoch[4940/20000], loss: 0.000064\n",
      "Epoch[4960/20000], loss: 0.000041\n",
      "Epoch[4980/20000], loss: 0.000079\n",
      "Epoch[5000/20000], loss: 0.000055\n",
      "Epoch[5020/20000], loss: 0.000050\n",
      "Epoch[5040/20000], loss: 0.000043\n",
      "Epoch[5060/20000], loss: 0.000040\n",
      "Epoch[5080/20000], loss: 0.000035\n",
      "Epoch[5100/20000], loss: 0.000039\n",
      "Epoch[5120/20000], loss: 0.000036\n",
      "Epoch[5140/20000], loss: 0.000038\n",
      "Epoch[5160/20000], loss: 0.000044\n",
      "Epoch[5180/20000], loss: 0.000046\n",
      "Epoch[5200/20000], loss: 0.000036\n",
      "Epoch[5220/20000], loss: 0.000048\n",
      "Epoch[5240/20000], loss: 0.000046\n",
      "Epoch[5260/20000], loss: 0.000040\n",
      "Epoch[5280/20000], loss: 0.000045\n",
      "Epoch[5300/20000], loss: 0.000041\n",
      "Epoch[5320/20000], loss: 0.000041\n",
      "Epoch[5340/20000], loss: 0.000043\n",
      "Epoch[5360/20000], loss: 0.000043\n",
      "Epoch[5380/20000], loss: 0.000039\n",
      "Epoch[5400/20000], loss: 0.000036\n",
      "Epoch[5420/20000], loss: 0.000048\n",
      "Epoch[5440/20000], loss: 0.000069\n",
      "Epoch[5460/20000], loss: 0.000028\n",
      "Epoch[5480/20000], loss: 0.000075\n",
      "Epoch[5500/20000], loss: 0.000025\n",
      "Epoch[5520/20000], loss: 0.000061\n",
      "Epoch[5540/20000], loss: 0.000041\n",
      "Epoch[5560/20000], loss: 0.000172\n",
      "Epoch[5580/20000], loss: 0.000098\n",
      "Epoch[5600/20000], loss: 0.000060\n",
      "Epoch[5620/20000], loss: 0.000104\n",
      "Epoch[5640/20000], loss: 0.000066\n",
      "Epoch[5660/20000], loss: 0.000050\n",
      "Epoch[5680/20000], loss: 0.000102\n",
      "Epoch[5700/20000], loss: 0.000069\n",
      "Epoch[5720/20000], loss: 0.000050\n",
      "Epoch[5740/20000], loss: 0.000099\n",
      "Epoch[5760/20000], loss: 0.000070\n",
      "Epoch[5780/20000], loss: 0.000051\n",
      "Epoch[5800/20000], loss: 0.000096\n",
      "Epoch[5820/20000], loss: 0.000062\n",
      "Epoch[5840/20000], loss: 0.000069\n",
      "Epoch[5860/20000], loss: 0.000053\n",
      "Epoch[5880/20000], loss: 0.000032\n",
      "Epoch[5900/20000], loss: 0.000136\n",
      "Epoch[5920/20000], loss: 0.000109\n",
      "Epoch[5940/20000], loss: 0.000031\n",
      "Epoch[5960/20000], loss: 0.000030\n",
      "Epoch[5980/20000], loss: 0.000087\n",
      "Epoch[6000/20000], loss: 0.000082\n",
      "Epoch[6020/20000], loss: 0.000059\n",
      "Epoch[6040/20000], loss: 0.000100\n",
      "Epoch[6060/20000], loss: 0.000074\n",
      "Epoch[6080/20000], loss: 0.000056\n",
      "Epoch[6100/20000], loss: 0.000096\n",
      "Epoch[6120/20000], loss: 0.000069\n",
      "Epoch[6140/20000], loss: 0.000050\n",
      "Epoch[6160/20000], loss: 0.000098\n",
      "Epoch[6180/20000], loss: 0.000068\n",
      "Epoch[6200/20000], loss: 0.000046\n",
      "Epoch[6220/20000], loss: 0.000068\n",
      "Epoch[6240/20000], loss: 0.000088\n",
      "Epoch[6260/20000], loss: 0.000028\n",
      "Epoch[6280/20000], loss: 0.000045\n",
      "Epoch[6300/20000], loss: 0.000059\n",
      "Epoch[6320/20000], loss: 0.000041\n",
      "Epoch[6340/20000], loss: 0.000046\n",
      "Epoch[6360/20000], loss: 0.000043\n",
      "Epoch[6380/20000], loss: 0.000048\n",
      "Epoch[6400/20000], loss: 0.000043\n",
      "Epoch[6420/20000], loss: 0.000039\n",
      "Epoch[6440/20000], loss: 0.000041\n",
      "Epoch[6460/20000], loss: 0.000037\n",
      "Epoch[6480/20000], loss: 0.000039\n",
      "Epoch[6500/20000], loss: 0.000041\n",
      "Epoch[6520/20000], loss: 0.000038\n",
      "Epoch[6540/20000], loss: 0.000041\n",
      "Epoch[6560/20000], loss: 0.000038\n",
      "Epoch[6580/20000], loss: 0.000036\n",
      "Epoch[6600/20000], loss: 0.000046\n",
      "Epoch[6620/20000], loss: 0.000041\n",
      "Epoch[6640/20000], loss: 0.000042\n",
      "Epoch[6660/20000], loss: 0.000043\n",
      "Epoch[6680/20000], loss: 0.000041\n",
      "Epoch[6700/20000], loss: 0.000038\n",
      "Epoch[6720/20000], loss: 0.000045\n",
      "Epoch[6740/20000], loss: 0.000040\n",
      "Epoch[6760/20000], loss: 0.000043\n",
      "Epoch[6780/20000], loss: 0.000044\n",
      "Epoch[6800/20000], loss: 0.000043\n",
      "Epoch[6820/20000], loss: 0.000051\n",
      "Epoch[6840/20000], loss: 0.000034\n",
      "Epoch[6860/20000], loss: 0.000058\n",
      "Epoch[6880/20000], loss: 0.000062\n",
      "Epoch[6900/20000], loss: 0.000036\n",
      "Epoch[6920/20000], loss: 0.000047\n",
      "Epoch[6940/20000], loss: 0.000029\n",
      "Epoch[6960/20000], loss: 0.000040\n",
      "Epoch[6980/20000], loss: 0.000034\n",
      "Epoch[7000/20000], loss: 0.000045\n",
      "Epoch[7020/20000], loss: 0.000036\n",
      "Epoch[7040/20000], loss: 0.000038\n",
      "Epoch[7060/20000], loss: 0.000036\n",
      "Epoch[7080/20000], loss: 0.000038\n",
      "Epoch[7100/20000], loss: 0.000033\n",
      "Epoch[7120/20000], loss: 0.000039\n",
      "Epoch[7140/20000], loss: 0.000041\n",
      "Epoch[7160/20000], loss: 0.000025\n",
      "Epoch[7180/20000], loss: 0.000041\n",
      "Epoch[7200/20000], loss: 0.000040\n",
      "Epoch[7220/20000], loss: 0.000031\n",
      "Epoch[7240/20000], loss: 0.000034\n",
      "Epoch[7260/20000], loss: 0.000038\n",
      "Epoch[7280/20000], loss: 0.000035\n",
      "Epoch[7300/20000], loss: 0.000041\n",
      "Epoch[7320/20000], loss: 0.000036\n",
      "Epoch[7340/20000], loss: 0.000038\n",
      "Epoch[7360/20000], loss: 0.000029\n",
      "Epoch[7380/20000], loss: 0.000048\n",
      "Epoch[7400/20000], loss: 0.000053\n",
      "Epoch[7420/20000], loss: 0.000048\n",
      "Epoch[7440/20000], loss: 0.000089\n",
      "Epoch[7460/20000], loss: 0.000080\n",
      "Epoch[7480/20000], loss: 0.000099\n",
      "Epoch[7500/20000], loss: 0.000071\n",
      "Epoch[7520/20000], loss: 0.000051\n",
      "Epoch[7540/20000], loss: 0.000103\n",
      "Epoch[7560/20000], loss: 0.000068\n",
      "Epoch[7580/20000], loss: 0.000054\n",
      "Epoch[7600/20000], loss: 0.000097\n",
      "Epoch[7620/20000], loss: 0.000070\n",
      "Epoch[7640/20000], loss: 0.000051\n",
      "Epoch[7660/20000], loss: 0.000026\n",
      "Epoch[7680/20000], loss: 0.000082\n",
      "Epoch[7700/20000], loss: 0.000099\n",
      "Epoch[7720/20000], loss: 0.000091\n",
      "Epoch[7740/20000], loss: 0.000038\n",
      "Epoch[7760/20000], loss: 0.000114\n",
      "Epoch[7780/20000], loss: 0.000063\n",
      "Epoch[7800/20000], loss: 0.000046\n",
      "Epoch[7820/20000], loss: 0.000100\n",
      "Epoch[7840/20000], loss: 0.000067\n",
      "Epoch[7860/20000], loss: 0.000051\n",
      "Epoch[7880/20000], loss: 0.000027\n",
      "Epoch[7900/20000], loss: 0.000027\n",
      "Epoch[7920/20000], loss: 0.000049\n",
      "Epoch[7940/20000], loss: 0.000033\n",
      "Epoch[7960/20000], loss: 0.000028\n",
      "Epoch[7980/20000], loss: 0.000033\n",
      "Epoch[8000/20000], loss: 0.000037\n",
      "Epoch[8020/20000], loss: 0.000039\n",
      "Epoch[8040/20000], loss: 0.000038\n",
      "Epoch[8060/20000], loss: 0.000034\n",
      "Epoch[8080/20000], loss: 0.000040\n",
      "Epoch[8100/20000], loss: 0.000050\n",
      "Epoch[8120/20000], loss: 0.000031\n",
      "Epoch[8140/20000], loss: 0.000047\n",
      "Epoch[8160/20000], loss: 0.000040\n",
      "Epoch[8180/20000], loss: 0.000045\n",
      "Epoch[8200/20000], loss: 0.000036\n",
      "Epoch[8220/20000], loss: 0.000038\n",
      "Epoch[8240/20000], loss: 0.000043\n",
      "Epoch[8260/20000], loss: 0.000038\n",
      "Epoch[8280/20000], loss: 0.000039\n",
      "Epoch[8300/20000], loss: 0.000040\n",
      "Epoch[8320/20000], loss: 0.000041\n",
      "Epoch[8340/20000], loss: 0.000040\n",
      "Epoch[8360/20000], loss: 0.000031\n",
      "Epoch[8380/20000], loss: 0.000046\n",
      "Epoch[8400/20000], loss: 0.000029\n",
      "Epoch[8420/20000], loss: 0.000035\n",
      "Epoch[8440/20000], loss: 0.000028\n",
      "Epoch[8460/20000], loss: 0.000049\n",
      "Epoch[8480/20000], loss: 0.000047\n",
      "Epoch[8500/20000], loss: 0.000049\n",
      "Epoch[8520/20000], loss: 0.000021\n",
      "Epoch[8540/20000], loss: 0.000108\n",
      "Epoch[8560/20000], loss: 0.000083\n",
      "Epoch[8580/20000], loss: 0.000056\n",
      "Epoch[8600/20000], loss: 0.000105\n",
      "Epoch[8620/20000], loss: 0.000073\n",
      "Epoch[8640/20000], loss: 0.000051\n",
      "Epoch[8660/20000], loss: 0.000098\n",
      "Epoch[8680/20000], loss: 0.000066\n",
      "Epoch[8700/20000], loss: 0.000047\n",
      "Epoch[8720/20000], loss: 0.000098\n",
      "Epoch[8740/20000], loss: 0.000067\n",
      "Epoch[8760/20000], loss: 0.000054\n",
      "Epoch[8780/20000], loss: 0.000098\n",
      "Epoch[8800/20000], loss: 0.000068\n",
      "Epoch[8820/20000], loss: 0.000059\n",
      "Epoch[8840/20000], loss: 0.000076\n",
      "Epoch[8860/20000], loss: 0.000106\n",
      "Epoch[8880/20000], loss: 0.000071\n",
      "Epoch[8900/20000], loss: 0.000033\n",
      "Epoch[8920/20000], loss: 0.000084\n",
      "Epoch[8940/20000], loss: 0.000237\n",
      "Epoch[8960/20000], loss: 0.000049\n",
      "Epoch[8980/20000], loss: 0.000066\n",
      "Epoch[9000/20000], loss: 0.000026\n",
      "Epoch[9020/20000], loss: 0.000065\n",
      "Epoch[9040/20000], loss: 0.000100\n",
      "Epoch[9060/20000], loss: 0.000068\n",
      "Epoch[9080/20000], loss: 0.000094\n",
      "Epoch[9100/20000], loss: 0.000067\n",
      "Epoch[9120/20000], loss: 0.000093\n",
      "Epoch[9140/20000], loss: 0.000080\n",
      "Epoch[9160/20000], loss: 0.000062\n",
      "Epoch[9180/20000], loss: 0.000091\n",
      "Epoch[9200/20000], loss: 0.000075\n",
      "Epoch[9220/20000], loss: 0.000054\n",
      "Epoch[9240/20000], loss: 0.000095\n",
      "Epoch[9260/20000], loss: 0.000074\n",
      "Epoch[9280/20000], loss: 0.000045\n",
      "Epoch[9300/20000], loss: 0.000093\n",
      "Epoch[9320/20000], loss: 0.000071\n",
      "Epoch[9340/20000], loss: 0.000050\n",
      "Epoch[9360/20000], loss: 0.000101\n",
      "Epoch[9380/20000], loss: 0.000069\n",
      "Epoch[9400/20000], loss: 0.000051\n",
      "Epoch[9420/20000], loss: 0.000090\n",
      "Epoch[9440/20000], loss: 0.000078\n",
      "Epoch[9460/20000], loss: 0.000045\n",
      "Epoch[9480/20000], loss: 0.000095\n",
      "Epoch[9500/20000], loss: 0.000063\n",
      "Epoch[9520/20000], loss: 0.000042\n",
      "Epoch[9540/20000], loss: 0.000052\n",
      "Epoch[9560/20000], loss: 0.000148\n",
      "Epoch[9580/20000], loss: 0.000065\n",
      "Epoch[9600/20000], loss: 0.000040\n",
      "Epoch[9620/20000], loss: 0.000112\n",
      "Epoch[9640/20000], loss: 0.000064\n",
      "Epoch[9660/20000], loss: 0.000049\n",
      "Epoch[9680/20000], loss: 0.000097\n",
      "Epoch[9700/20000], loss: 0.000069\n",
      "Epoch[9720/20000], loss: 0.000052\n",
      "Epoch[9740/20000], loss: 0.000098\n",
      "Epoch[9760/20000], loss: 0.000064\n",
      "Epoch[9780/20000], loss: 0.000039\n",
      "Epoch[9800/20000], loss: 0.000032\n",
      "Epoch[9820/20000], loss: 0.000040\n",
      "Epoch[9840/20000], loss: 0.000066\n",
      "Epoch[9860/20000], loss: 0.000124\n",
      "Epoch[9880/20000], loss: 0.000065\n",
      "Epoch[9900/20000], loss: 0.000051\n",
      "Epoch[9920/20000], loss: 0.000103\n",
      "Epoch[9940/20000], loss: 0.000066\n",
      "Epoch[9960/20000], loss: 0.000050\n",
      "Epoch[9980/20000], loss: 0.000097\n",
      "Epoch[10000/20000], loss: 0.000070\n",
      "Epoch[10020/20000], loss: 0.000055\n",
      "Epoch[10040/20000], loss: 0.000097\n",
      "Epoch[10060/20000], loss: 0.000066\n",
      "Epoch[10080/20000], loss: 0.000062\n",
      "Epoch[10100/20000], loss: 0.000043\n",
      "Epoch[10120/20000], loss: 0.000100\n",
      "Epoch[10140/20000], loss: 0.000071\n",
      "Epoch[10160/20000], loss: 0.000055\n",
      "Epoch[10180/20000], loss: 0.000080\n",
      "Epoch[10200/20000], loss: 0.000013\n",
      "Epoch[10220/20000], loss: 0.000029\n",
      "Epoch[10240/20000], loss: 0.000048\n",
      "Epoch[10260/20000], loss: 0.000037\n",
      "Epoch[10280/20000], loss: 0.000041\n",
      "Epoch[10300/20000], loss: 0.000035\n",
      "Epoch[10320/20000], loss: 0.000044\n",
      "Epoch[10340/20000], loss: 0.000033\n",
      "Epoch[10360/20000], loss: 0.000027\n",
      "Epoch[10380/20000], loss: 0.000040\n",
      "Epoch[10400/20000], loss: 0.000039\n",
      "Epoch[10420/20000], loss: 0.000038\n",
      "Epoch[10440/20000], loss: 0.000039\n",
      "Epoch[10460/20000], loss: 0.000036\n",
      "Epoch[10480/20000], loss: 0.000030\n",
      "Epoch[10500/20000], loss: 0.000046\n",
      "Epoch[10520/20000], loss: 0.000048\n",
      "Epoch[10540/20000], loss: 0.000022\n",
      "Epoch[10560/20000], loss: 0.000041\n",
      "Epoch[10580/20000], loss: 0.000036\n",
      "Epoch[10600/20000], loss: 0.000028\n",
      "Epoch[10620/20000], loss: 0.000020\n",
      "Epoch[10640/20000], loss: 0.000026\n",
      "Epoch[10660/20000], loss: 0.000092\n",
      "Epoch[10680/20000], loss: 0.000093\n",
      "Epoch[10700/20000], loss: 0.000078\n",
      "Epoch[10720/20000], loss: 0.000052\n",
      "Epoch[10740/20000], loss: 0.000104\n",
      "Epoch[10760/20000], loss: 0.000067\n",
      "Epoch[10780/20000], loss: 0.000050\n",
      "Epoch[10800/20000], loss: 0.000100\n",
      "Epoch[10820/20000], loss: 0.000063\n",
      "Epoch[10840/20000], loss: 0.000050\n",
      "Epoch[10860/20000], loss: 0.000103\n",
      "Epoch[10880/20000], loss: 0.000072\n",
      "Epoch[10900/20000], loss: 0.000052\n",
      "Epoch[10920/20000], loss: 0.000101\n",
      "Epoch[10940/20000], loss: 0.000065\n",
      "Epoch[10960/20000], loss: 0.000048\n",
      "Epoch[10980/20000], loss: 0.000090\n",
      "Epoch[11000/20000], loss: 0.000038\n",
      "Epoch[11020/20000], loss: 0.000046\n",
      "Epoch[11040/20000], loss: 0.000024\n",
      "Epoch[11060/20000], loss: 0.000106\n",
      "Epoch[11080/20000], loss: 0.000078\n",
      "Epoch[11100/20000], loss: 0.000049\n",
      "Epoch[11120/20000], loss: 0.000104\n",
      "Epoch[11140/20000], loss: 0.000070\n",
      "Epoch[11160/20000], loss: 0.000051\n",
      "Epoch[11180/20000], loss: 0.000102\n",
      "Epoch[11200/20000], loss: 0.000066\n",
      "Epoch[11220/20000], loss: 0.000049\n",
      "Epoch[11240/20000], loss: 0.000094\n",
      "Epoch[11260/20000], loss: 0.000065\n",
      "Epoch[11280/20000], loss: 0.000060\n",
      "Epoch[11300/20000], loss: 0.000042\n",
      "Epoch[11320/20000], loss: 0.000046\n",
      "Epoch[11340/20000], loss: 0.000047\n",
      "Epoch[11360/20000], loss: 0.000042\n",
      "Epoch[11380/20000], loss: 0.000034\n",
      "Epoch[11400/20000], loss: 0.000040\n",
      "Epoch[11420/20000], loss: 0.000042\n",
      "Epoch[11440/20000], loss: 0.000041\n",
      "Epoch[11460/20000], loss: 0.000034\n",
      "Epoch[11480/20000], loss: 0.000041\n",
      "Epoch[11500/20000], loss: 0.000050\n",
      "Epoch[11520/20000], loss: 0.000036\n",
      "Epoch[11540/20000], loss: 0.000042\n",
      "Epoch[11560/20000], loss: 0.000050\n",
      "Epoch[11580/20000], loss: 0.000059\n",
      "Epoch[11600/20000], loss: 0.000057\n",
      "Epoch[11620/20000], loss: 0.000038\n",
      "Epoch[11640/20000], loss: 0.000033\n",
      "Epoch[11660/20000], loss: 0.000045\n",
      "Epoch[11680/20000], loss: 0.000045\n",
      "Epoch[11700/20000], loss: 0.000036\n",
      "Epoch[11720/20000], loss: 0.000045\n",
      "Epoch[11740/20000], loss: 0.000057\n",
      "Epoch[11760/20000], loss: 0.000038\n",
      "Epoch[11780/20000], loss: 0.000050\n",
      "Epoch[11800/20000], loss: 0.000053\n",
      "Epoch[11820/20000], loss: 0.000176\n",
      "Epoch[11840/20000], loss: 0.000081\n",
      "Epoch[11860/20000], loss: 0.000036\n",
      "Epoch[11880/20000], loss: 0.000096\n",
      "Epoch[11900/20000], loss: 0.000062\n",
      "Epoch[11920/20000], loss: 0.000050\n",
      "Epoch[11940/20000], loss: 0.000101\n",
      "Epoch[11960/20000], loss: 0.000067\n",
      "Epoch[11980/20000], loss: 0.000054\n",
      "Epoch[12000/20000], loss: 0.000091\n",
      "Epoch[12020/20000], loss: 0.000016\n",
      "Epoch[12040/20000], loss: 0.000038\n",
      "Epoch[12060/20000], loss: 0.000116\n",
      "Epoch[12080/20000], loss: 0.000113\n",
      "Epoch[12100/20000], loss: 0.000144\n",
      "Epoch[12120/20000], loss: 0.000102\n",
      "Epoch[12140/20000], loss: 0.000053\n",
      "Epoch[12160/20000], loss: 0.000122\n",
      "Epoch[12180/20000], loss: 0.000061\n",
      "Epoch[12200/20000], loss: 0.000052\n",
      "Epoch[12220/20000], loss: 0.000103\n",
      "Epoch[12240/20000], loss: 0.000062\n",
      "Epoch[12260/20000], loss: 0.000045\n",
      "Epoch[12280/20000], loss: 0.000033\n",
      "Epoch[12300/20000], loss: 0.000040\n",
      "Epoch[12320/20000], loss: 0.000041\n",
      "Epoch[12340/20000], loss: 0.000044\n",
      "Epoch[12360/20000], loss: 0.000038\n",
      "Epoch[12380/20000], loss: 0.000035\n",
      "Epoch[12400/20000], loss: 0.000038\n",
      "Epoch[12420/20000], loss: 0.000037\n",
      "Epoch[12440/20000], loss: 0.000029\n",
      "Epoch[12460/20000], loss: 0.000043\n",
      "Epoch[12480/20000], loss: 0.000047\n",
      "Epoch[12500/20000], loss: 0.000026\n",
      "Epoch[12520/20000], loss: 0.000036\n",
      "Epoch[12540/20000], loss: 0.000032\n",
      "Epoch[12560/20000], loss: 0.000031\n",
      "Epoch[12580/20000], loss: 0.000037\n",
      "Epoch[12600/20000], loss: 0.000048\n",
      "Epoch[12620/20000], loss: 0.000042\n",
      "Epoch[12640/20000], loss: 0.000033\n",
      "Epoch[12660/20000], loss: 0.000037\n",
      "Epoch[12680/20000], loss: 0.000037\n",
      "Epoch[12700/20000], loss: 0.000035\n",
      "Epoch[12720/20000], loss: 0.000037\n",
      "Epoch[12740/20000], loss: 0.000037\n",
      "Epoch[12760/20000], loss: 0.000034\n",
      "Epoch[12780/20000], loss: 0.000029\n",
      "Epoch[12800/20000], loss: 0.000044\n",
      "Epoch[12820/20000], loss: 0.000035\n",
      "Epoch[12840/20000], loss: 0.000040\n",
      "Epoch[12860/20000], loss: 0.000030\n",
      "Epoch[12880/20000], loss: 0.000035\n",
      "Epoch[12900/20000], loss: 0.000038\n",
      "Epoch[12920/20000], loss: 0.000035\n",
      "Epoch[12940/20000], loss: 0.000036\n",
      "Epoch[12960/20000], loss: 0.000032\n",
      "Epoch[12980/20000], loss: 0.000034\n",
      "Epoch[13000/20000], loss: 0.000035\n",
      "Epoch[13020/20000], loss: 0.000030\n",
      "Epoch[13040/20000], loss: 0.000031\n",
      "Epoch[13060/20000], loss: 0.000031\n",
      "Epoch[13080/20000], loss: 0.000031\n",
      "Epoch[13100/20000], loss: 0.000048\n",
      "Epoch[13120/20000], loss: 0.000042\n",
      "Epoch[13140/20000], loss: 0.000044\n",
      "Epoch[13160/20000], loss: 0.000040\n",
      "Epoch[13180/20000], loss: 0.000016\n",
      "Epoch[13200/20000], loss: 0.000144\n",
      "Epoch[13220/20000], loss: 0.000146\n",
      "Epoch[13240/20000], loss: 0.000166\n",
      "Epoch[13260/20000], loss: 0.000146\n",
      "Epoch[13280/20000], loss: 0.000155\n",
      "Epoch[13300/20000], loss: 0.000146\n",
      "Epoch[13320/20000], loss: 0.000149\n",
      "Epoch[13340/20000], loss: 0.000134\n",
      "Epoch[13360/20000], loss: 0.000071\n",
      "Epoch[13380/20000], loss: 0.000032\n",
      "Epoch[13400/20000], loss: 0.000037\n",
      "Epoch[13420/20000], loss: 0.000041\n",
      "Epoch[13440/20000], loss: 0.000035\n",
      "Epoch[13460/20000], loss: 0.000028\n",
      "Epoch[13480/20000], loss: 0.000037\n",
      "Epoch[13500/20000], loss: 0.000055\n",
      "Epoch[13520/20000], loss: 0.000036\n",
      "Epoch[13540/20000], loss: 0.000033\n",
      "Epoch[13560/20000], loss: 0.000039\n",
      "Epoch[13580/20000], loss: 0.000037\n",
      "Epoch[13600/20000], loss: 0.000035\n",
      "Epoch[13620/20000], loss: 0.000037\n",
      "Epoch[13640/20000], loss: 0.000037\n",
      "Epoch[13660/20000], loss: 0.000045\n",
      "Epoch[13680/20000], loss: 0.000032\n",
      "Epoch[13700/20000], loss: 0.000034\n",
      "Epoch[13720/20000], loss: 0.000046\n",
      "Epoch[13740/20000], loss: 0.000031\n",
      "Epoch[13760/20000], loss: 0.000029\n",
      "Epoch[13780/20000], loss: 0.000038\n",
      "Epoch[13800/20000], loss: 0.000035\n",
      "Epoch[13820/20000], loss: 0.000036\n",
      "Epoch[13840/20000], loss: 0.000033\n",
      "Epoch[13860/20000], loss: 0.000039\n",
      "Epoch[13880/20000], loss: 0.000034\n",
      "Epoch[13900/20000], loss: 0.000036\n",
      "Epoch[13920/20000], loss: 0.000043\n",
      "Epoch[13940/20000], loss: 0.000029\n",
      "Epoch[13960/20000], loss: 0.000036\n",
      "Epoch[13980/20000], loss: 0.000039\n",
      "Epoch[14000/20000], loss: 0.000040\n",
      "Epoch[14020/20000], loss: 0.000040\n",
      "Epoch[14040/20000], loss: 0.000036\n",
      "Epoch[14060/20000], loss: 0.000042\n",
      "Epoch[14080/20000], loss: 0.000045\n",
      "Epoch[14100/20000], loss: 0.000036\n",
      "Epoch[14120/20000], loss: 0.000041\n",
      "Epoch[14140/20000], loss: 0.000036\n",
      "Epoch[14160/20000], loss: 0.000035\n",
      "Epoch[14180/20000], loss: 0.000029\n",
      "Epoch[14200/20000], loss: 0.000059\n",
      "Epoch[14220/20000], loss: 0.000029\n",
      "Epoch[14240/20000], loss: 0.000090\n",
      "Epoch[14260/20000], loss: 0.000077\n",
      "Epoch[14280/20000], loss: 0.000061\n",
      "Epoch[14300/20000], loss: 0.000103\n",
      "Epoch[14320/20000], loss: 0.000063\n",
      "Epoch[14340/20000], loss: 0.000047\n",
      "Epoch[14360/20000], loss: 0.000100\n",
      "Epoch[14380/20000], loss: 0.000069\n",
      "Epoch[14400/20000], loss: 0.000052\n",
      "Epoch[14420/20000], loss: 0.000096\n",
      "Epoch[14440/20000], loss: 0.000066\n",
      "Epoch[14460/20000], loss: 0.000051\n",
      "Epoch[14480/20000], loss: 0.000101\n",
      "Epoch[14500/20000], loss: 0.000065\n",
      "Epoch[14520/20000], loss: 0.000053\n",
      "Epoch[14540/20000], loss: 0.000097\n",
      "Epoch[14560/20000], loss: 0.000069\n",
      "Epoch[14580/20000], loss: 0.000042\n",
      "Epoch[14600/20000], loss: 0.000100\n",
      "Epoch[14620/20000], loss: 0.000056\n",
      "Epoch[14640/20000], loss: 0.000061\n",
      "Epoch[14660/20000], loss: 0.000094\n",
      "Epoch[14680/20000], loss: 0.000065\n",
      "Epoch[14700/20000], loss: 0.000044\n",
      "Epoch[14720/20000], loss: 0.000102\n",
      "Epoch[14740/20000], loss: 0.000065\n",
      "Epoch[14760/20000], loss: 0.000044\n",
      "Epoch[14780/20000], loss: 0.000110\n",
      "Epoch[14800/20000], loss: 0.000077\n",
      "Epoch[14820/20000], loss: 0.000055\n",
      "Epoch[14840/20000], loss: 0.000093\n",
      "Epoch[14860/20000], loss: 0.000062\n",
      "Epoch[14880/20000], loss: 0.000042\n",
      "Epoch[14900/20000], loss: 0.000105\n",
      "Epoch[14920/20000], loss: 0.000081\n",
      "Epoch[14940/20000], loss: 0.000053\n",
      "Epoch[14960/20000], loss: 0.000100\n",
      "Epoch[14980/20000], loss: 0.000063\n",
      "Epoch[15000/20000], loss: 0.000051\n",
      "Epoch[15020/20000], loss: 0.000094\n",
      "Epoch[15040/20000], loss: 0.000061\n",
      "Epoch[15060/20000], loss: 0.000063\n",
      "Epoch[15080/20000], loss: 0.000087\n",
      "Epoch[15100/20000], loss: 0.000039\n",
      "Epoch[15120/20000], loss: 0.000041\n",
      "Epoch[15140/20000], loss: 0.000040\n",
      "Epoch[15160/20000], loss: 0.000039\n",
      "Epoch[15180/20000], loss: 0.000050\n",
      "Epoch[15200/20000], loss: 0.000028\n",
      "Epoch[15220/20000], loss: 0.000043\n",
      "Epoch[15240/20000], loss: 0.000034\n",
      "Epoch[15260/20000], loss: 0.000043\n",
      "Epoch[15280/20000], loss: 0.000040\n",
      "Epoch[15300/20000], loss: 0.000036\n",
      "Epoch[15320/20000], loss: 0.000042\n",
      "Epoch[15340/20000], loss: 0.000041\n",
      "Epoch[15360/20000], loss: 0.000052\n",
      "Epoch[15380/20000], loss: 0.000034\n",
      "Epoch[15400/20000], loss: 0.000083\n",
      "Epoch[15420/20000], loss: 0.000112\n",
      "Epoch[15440/20000], loss: 0.000078\n",
      "Epoch[15460/20000], loss: 0.000048\n",
      "Epoch[15480/20000], loss: 0.000097\n",
      "Epoch[15500/20000], loss: 0.000072\n",
      "Epoch[15520/20000], loss: 0.000051\n",
      "Epoch[15540/20000], loss: 0.000100\n",
      "Epoch[15560/20000], loss: 0.000067\n",
      "Epoch[15580/20000], loss: 0.000054\n",
      "Epoch[15600/20000], loss: 0.000091\n",
      "Epoch[15620/20000], loss: 0.000069\n",
      "Epoch[15640/20000], loss: 0.000079\n",
      "Epoch[15660/20000], loss: 0.000066\n",
      "Epoch[15680/20000], loss: 0.000107\n",
      "Epoch[15700/20000], loss: 0.000060\n",
      "Epoch[15720/20000], loss: 0.000051\n",
      "Epoch[15740/20000], loss: 0.000094\n",
      "Epoch[15760/20000], loss: 0.000065\n",
      "Epoch[15780/20000], loss: 0.000053\n",
      "Epoch[15800/20000], loss: 0.000075\n",
      "Epoch[15820/20000], loss: 0.000036\n",
      "Epoch[15840/20000], loss: 0.000043\n",
      "Epoch[15860/20000], loss: 0.000037\n",
      "Epoch[15880/20000], loss: 0.000040\n",
      "Epoch[15900/20000], loss: 0.000034\n",
      "Epoch[15920/20000], loss: 0.000034\n",
      "Epoch[15940/20000], loss: 0.000046\n",
      "Epoch[15960/20000], loss: 0.000037\n",
      "Epoch[15980/20000], loss: 0.000034\n",
      "Epoch[16000/20000], loss: 0.000033\n",
      "Epoch[16020/20000], loss: 0.000033\n",
      "Epoch[16040/20000], loss: 0.000046\n",
      "Epoch[16060/20000], loss: 0.000032\n",
      "Epoch[16080/20000], loss: 0.000036\n",
      "Epoch[16100/20000], loss: 0.000072\n",
      "Epoch[16120/20000], loss: 0.000186\n",
      "Epoch[16140/20000], loss: 0.000162\n",
      "Epoch[16160/20000], loss: 0.000158\n",
      "Epoch[16180/20000], loss: 0.000148\n",
      "Epoch[16200/20000], loss: 0.000154\n",
      "Epoch[16220/20000], loss: 0.000145\n",
      "Epoch[16240/20000], loss: 0.000149\n",
      "Epoch[16260/20000], loss: 0.000081\n",
      "Epoch[16280/20000], loss: 0.000057\n",
      "Epoch[16300/20000], loss: 0.000047\n",
      "Epoch[16320/20000], loss: 0.000055\n",
      "Epoch[16340/20000], loss: 0.000143\n",
      "Epoch[16360/20000], loss: 0.000069\n",
      "Epoch[16380/20000], loss: 0.000047\n",
      "Epoch[16400/20000], loss: 0.000101\n",
      "Epoch[16420/20000], loss: 0.000069\n",
      "Epoch[16440/20000], loss: 0.000055\n",
      "Epoch[16460/20000], loss: 0.000093\n",
      "Epoch[16480/20000], loss: 0.000069\n",
      "Epoch[16500/20000], loss: 0.000043\n",
      "Epoch[16520/20000], loss: 0.000133\n",
      "Epoch[16540/20000], loss: 0.000051\n",
      "Epoch[16560/20000], loss: 0.000021\n",
      "Epoch[16580/20000], loss: 0.000046\n",
      "Epoch[16600/20000], loss: 0.000038\n",
      "Epoch[16620/20000], loss: 0.000034\n",
      "Epoch[16640/20000], loss: 0.000039\n",
      "Epoch[16660/20000], loss: 0.000036\n",
      "Epoch[16680/20000], loss: 0.000035\n",
      "Epoch[16700/20000], loss: 0.000044\n",
      "Epoch[16720/20000], loss: 0.000039\n",
      "Epoch[16740/20000], loss: 0.000041\n",
      "Epoch[16760/20000], loss: 0.000034\n",
      "Epoch[16780/20000], loss: 0.000037\n",
      "Epoch[16800/20000], loss: 0.000048\n",
      "Epoch[16820/20000], loss: 0.000035\n",
      "Epoch[16840/20000], loss: 0.000042\n",
      "Epoch[16860/20000], loss: 0.000025\n",
      "Epoch[16880/20000], loss: 0.000034\n",
      "Epoch[16900/20000], loss: 0.000035\n",
      "Epoch[16920/20000], loss: 0.000041\n",
      "Epoch[16940/20000], loss: 0.000031\n",
      "Epoch[16960/20000], loss: 0.000042\n",
      "Epoch[16980/20000], loss: 0.000040\n",
      "Epoch[17000/20000], loss: 0.000027\n",
      "Epoch[17020/20000], loss: 0.000045\n",
      "Epoch[17040/20000], loss: 0.000041\n",
      "Epoch[17060/20000], loss: 0.000040\n",
      "Epoch[17080/20000], loss: 0.000042\n",
      "Epoch[17100/20000], loss: 0.000032\n",
      "Epoch[17120/20000], loss: 0.000042\n",
      "Epoch[17140/20000], loss: 0.000031\n",
      "Epoch[17160/20000], loss: 0.000032\n",
      "Epoch[17180/20000], loss: 0.000046\n",
      "Epoch[17200/20000], loss: 0.000031\n",
      "Epoch[17220/20000], loss: 0.000039\n",
      "Epoch[17240/20000], loss: 0.000039\n",
      "Epoch[17260/20000], loss: 0.000037\n",
      "Epoch[17280/20000], loss: 0.000046\n",
      "Epoch[17300/20000], loss: 0.000045\n",
      "Epoch[17320/20000], loss: 0.000034\n",
      "Epoch[17340/20000], loss: 0.000040\n",
      "Epoch[17360/20000], loss: 0.000035\n",
      "Epoch[17380/20000], loss: 0.000034\n",
      "Epoch[17400/20000], loss: 0.000028\n",
      "Epoch[17420/20000], loss: 0.000060\n",
      "Epoch[17440/20000], loss: 0.000136\n",
      "Epoch[17460/20000], loss: 0.000061\n",
      "Epoch[17480/20000], loss: 0.000092\n",
      "Epoch[17500/20000], loss: 0.000093\n",
      "Epoch[17520/20000], loss: 0.000051\n",
      "Epoch[17540/20000], loss: 0.000071\n",
      "Epoch[17560/20000], loss: 0.000053\n",
      "Epoch[17580/20000], loss: 0.000050\n",
      "Epoch[17600/20000], loss: 0.000058\n",
      "Epoch[17620/20000], loss: 0.000045\n",
      "Epoch[17640/20000], loss: 0.000049\n",
      "Epoch[17660/20000], loss: 0.000045\n",
      "Epoch[17680/20000], loss: 0.000049\n",
      "Epoch[17700/20000], loss: 0.000039\n",
      "Epoch[17720/20000], loss: 0.000040\n",
      "Epoch[17740/20000], loss: 0.000040\n",
      "Epoch[17760/20000], loss: 0.000046\n",
      "Epoch[17780/20000], loss: 0.000065\n",
      "Epoch[17800/20000], loss: 0.000012\n",
      "Epoch[17820/20000], loss: 0.000072\n",
      "Epoch[17840/20000], loss: 0.000020\n",
      "Epoch[17860/20000], loss: 0.000104\n",
      "Epoch[17880/20000], loss: 0.000036\n",
      "Epoch[17900/20000], loss: 0.000115\n",
      "Epoch[17920/20000], loss: 0.000088\n",
      "Epoch[17940/20000], loss: 0.000051\n",
      "Epoch[17960/20000], loss: 0.000104\n",
      "Epoch[17980/20000], loss: 0.000067\n",
      "Epoch[18000/20000], loss: 0.000050\n",
      "Epoch[18020/20000], loss: 0.000101\n",
      "Epoch[18040/20000], loss: 0.000070\n",
      "Epoch[18060/20000], loss: 0.000052\n",
      "Epoch[18080/20000], loss: 0.000094\n",
      "Epoch[18100/20000], loss: 0.000062\n",
      "Epoch[18120/20000], loss: 0.000034\n",
      "Epoch[18140/20000], loss: 0.000074\n",
      "Epoch[18160/20000], loss: 0.000048\n",
      "Epoch[18180/20000], loss: 0.000057\n",
      "Epoch[18200/20000], loss: 0.000057\n",
      "Epoch[18220/20000], loss: 0.000030\n",
      "Epoch[18240/20000], loss: 0.000061\n",
      "Epoch[18260/20000], loss: 0.000027\n",
      "Epoch[18280/20000], loss: 0.000057\n",
      "Epoch[18300/20000], loss: 0.000057\n",
      "Epoch[18320/20000], loss: 0.000043\n",
      "Epoch[18340/20000], loss: 0.000044\n",
      "Epoch[18360/20000], loss: 0.000043\n",
      "Epoch[18380/20000], loss: 0.000045\n",
      "Epoch[18400/20000], loss: 0.000034\n",
      "Epoch[18420/20000], loss: 0.000043\n",
      "Epoch[18440/20000], loss: 0.000046\n",
      "Epoch[18460/20000], loss: 0.000036\n",
      "Epoch[18480/20000], loss: 0.000041\n",
      "Epoch[18500/20000], loss: 0.000047\n",
      "Epoch[18520/20000], loss: 0.000041\n",
      "Epoch[18540/20000], loss: 0.000035\n",
      "Epoch[18560/20000], loss: 0.000040\n",
      "Epoch[18580/20000], loss: 0.000039\n",
      "Epoch[18600/20000], loss: 0.000036\n",
      "Epoch[18620/20000], loss: 0.000033\n",
      "Epoch[18640/20000], loss: 0.000053\n",
      "Epoch[18660/20000], loss: 0.000026\n",
      "Epoch[18680/20000], loss: 0.000063\n",
      "Epoch[18700/20000], loss: 0.000077\n",
      "Epoch[18720/20000], loss: 0.000060\n",
      "Epoch[18740/20000], loss: 0.000103\n",
      "Epoch[18760/20000], loss: 0.000063\n",
      "Epoch[18780/20000], loss: 0.000046\n",
      "Epoch[18800/20000], loss: 0.000093\n",
      "Epoch[18820/20000], loss: 0.000063\n",
      "Epoch[18840/20000], loss: 0.000052\n",
      "Epoch[18860/20000], loss: 0.000100\n",
      "Epoch[18880/20000], loss: 0.000072\n",
      "Epoch[18900/20000], loss: 0.000042\n",
      "Epoch[18920/20000], loss: 0.000103\n",
      "Epoch[18940/20000], loss: 0.000067\n",
      "Epoch[18960/20000], loss: 0.000050\n",
      "Epoch[18980/20000], loss: 0.000096\n",
      "Epoch[19000/20000], loss: 0.000072\n",
      "Epoch[19020/20000], loss: 0.000056\n",
      "Epoch[19040/20000], loss: 0.000096\n",
      "Epoch[19060/20000], loss: 0.000062\n",
      "Epoch[19080/20000], loss: 0.000038\n",
      "Epoch[19100/20000], loss: 0.000109\n",
      "Epoch[19120/20000], loss: 0.000062\n",
      "Epoch[19140/20000], loss: 0.000048\n",
      "Epoch[19160/20000], loss: 0.000101\n",
      "Epoch[19180/20000], loss: 0.000064\n",
      "Epoch[19200/20000], loss: 0.000054\n",
      "Epoch[19220/20000], loss: 0.000102\n",
      "Epoch[19240/20000], loss: 0.000060\n",
      "Epoch[19260/20000], loss: 0.000048\n",
      "Epoch[19280/20000], loss: 0.000077\n",
      "Epoch[19300/20000], loss: 0.000079\n",
      "Epoch[19320/20000], loss: 0.000052\n",
      "Epoch[19340/20000], loss: 0.000105\n",
      "Epoch[19360/20000], loss: 0.000063\n",
      "Epoch[19380/20000], loss: 0.000055\n",
      "Epoch[19400/20000], loss: 0.000102\n",
      "Epoch[19420/20000], loss: 0.000065\n",
      "Epoch[19440/20000], loss: 0.000050\n",
      "Epoch[19460/20000], loss: 0.000097\n",
      "Epoch[19480/20000], loss: 0.000066\n",
      "Epoch[19500/20000], loss: 0.000045\n",
      "Epoch[19520/20000], loss: 0.000102\n",
      "Epoch[19540/20000], loss: 0.000062\n",
      "Epoch[19560/20000], loss: 0.000043\n",
      "Epoch[19580/20000], loss: 0.000088\n",
      "Epoch[19600/20000], loss: 0.000080\n",
      "Epoch[19620/20000], loss: 0.000074\n",
      "Epoch[19640/20000], loss: 0.000071\n",
      "Epoch[19660/20000], loss: 0.000017\n",
      "Epoch[19680/20000], loss: 0.000108\n",
      "Epoch[19700/20000], loss: 0.000047\n",
      "Epoch[19720/20000], loss: 0.000049\n",
      "Epoch[19740/20000], loss: 0.000032\n",
      "Epoch[19760/20000], loss: 0.000039\n",
      "Epoch[19780/20000], loss: 0.000045\n",
      "Epoch[19800/20000], loss: 0.000037\n",
      "Epoch[19820/20000], loss: 0.000040\n",
      "Epoch[19840/20000], loss: 0.000041\n",
      "Epoch[19860/20000], loss: 0.000039\n",
      "Epoch[19880/20000], loss: 0.000040\n",
      "Epoch[19900/20000], loss: 0.000046\n",
      "Epoch[19920/20000], loss: 0.000041\n",
      "Epoch[19940/20000], loss: 0.000043\n",
      "Epoch[19960/20000], loss: 0.000035\n",
      "Epoch[19980/20000], loss: 0.000031\n",
      "Epoch[20000/20000], loss: 0.000037\n",
      "tensor([[1.0000, 0.6833]])\n"
     ]
    }
   ],
   "source": [
    "from math import isnan\r\n",
    "num_epochs = 20000\r\n",
    "for epoch in range(num_epochs):\r\n",
    "     inputs = Variable(x_train)\r\n",
    "     # forward\r\n",
    "     out,loss = model(inputs)  # 前向传播\r\n",
    "     #while isnan(loss.data.item()):\r\n",
    "     #    out,loss = model(inputs)  # 前向传播\r\n",
    "     # backward\r\n",
    "     optimizer.zero_grad() # 梯度归零\r\n",
    "     loss.backward() # 反向传播\r\n",
    "     optimizer.step() # 更新参数\r\n",
    "     if (epoch + 1) % 20 == 0:\r\n",
    "         \r\n",
    "         print('Epoch[{}/{}], loss: {:.6f}'.format(epoch + 1, num_epochs,loss.data.item()))\r\n",
    "model.eval()\r\n",
    "predict = model(Variable(x_train))\r\n",
    "print(predict[0].data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "PaddlePaddle 1.2.0 (Python 3.5)",
   "language": "python",
   "name": "py35-paddle1.2.0"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
